package Card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    static final String[] suits= {"♥️","♠️","♣️","♦️"};

    public List<Card> buyCards(){
        List<Card> cardList = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                Card newCard = new Card(suits[j],i );
                cardList.add(newCard);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList){
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            int j = random.nextInt(i);
            swap(cardList,i,j);
        }
    }

    void swap(List<Card> cardList,int i,int j){
        Card tmp = cardList.get(j);
        cardList.set(j,cardList.get(i));
        cardList.set(i,tmp);
    }

    public void play(List<Card> cardList){
        List<List<Card>> Person = new ArrayList<>(3);
        List<Card> p1 = new ArrayList<>();
        List<Card> p2 = new ArrayList<>();
        List<Card> p3 = new ArrayList<>();
        Person.add(p1);
        Person.add(p2);
        Person.add(p3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.removeFirst();
                Person.get(j).add(card);
            }
        }
    }
}
